<template>
<view class="container">
  <block v-if="record_list.length > 0">
    <block v-for="(item, index) in record_list" :key="index">
      <view class="jy_xq_box" @tap="showDetail" :data-index="index">
        <view class="jy jy_zong">
          <view class="left">{{item.time_txt}}</view>
          <view class="right margin_r">{{item.desc}}</view>
        </view>
        <view :class="'jy_xq ' + (showIndex != index  ? 'hide' : '')">
          <view class="jy_jl" v-if="item.money_add > 0">
            <view class="left"><lang keywords="余额增加"></lang>：</view>
            <view class="right margin_r">{{currency + item.money_add}}</view>
          </view>
          <view class="jy_jl" v-if="item.money_use > 0">
            <view class="left"><lang keywords="余额减少"></lang>：</view>
            <view class="right margin_r">{{currency + item.money_use}}</view>
          </view>
          <view class="jy_jl" v-if="item.score_add > 0">
            <view class="left"><lang keywords="积分增加"></lang>：</view>
            <view class="right margin_r">{{item.score_add}}分</view>
          </view>
          <view class="jy_jl" v-if="item.score_use > 0">
            <view class="left"><lang keywords="积分减少"></lang>：</view>
            <view class="right margin_r">{{item.score_use}}分</view>
          </view>
          <view class="jy_jl" v-if="item.coupon_add > 0">
            <view class="left"><lang keywords="优惠券增加"></lang>：</view>
            <view class="right margin_r">{{currency + item.coupon_add}}</view>
          </view>
          <view class="jy_jl" v-if="item.coupon_use > 0">
            <view class="left"><lang keywords="优惠券减少"></lang>：</view>
            <view class="right margin_r">{{currency + item.coupon_use}}</view>
          </view>
        </view>
      </view>
    </block>
  </block>
  <block v-else-if="isLoading == false">
    <view class="noneList"><lang keywords="暂无交易记录"></lang></view>
  </block>
</view>
</template>

"<script>
import common from '../../utils/common.js'
var app = getApp();

export default {
  data() {
    return {
      mer_id: 0,
      record_list: [],
      isLoading: true,
      showIndex: -1,
	  currency: '¥'
    };
  },

  onShareAppMessage: function () {},
  onReachBottom: function () {},
  onPullDownRefresh: function () {},
  onUnload: function () {},
  onHide: function () {},
  onShow: function () {},
  onReady: function () {},
  onLoad: function (options) {
    if (!options.mer_id) {
      options.mer_id = app.merchantOwn.mer_id;
    }

    this.setData({
      mer_id: options.mer_id
    });

    if (!app.globalData.userInfo) {
      var that = this; //调用应用实例的方法获取全局数据

      common.getUserInfo(function (userInfo) {
        if (!userInfo.phone) {
          wx.navigateTo({
            url: "../my/newnumber"
          });
        } else {
          that.setMainContent();
        }
      }, 'setting');
    } else {
      this.setMainContent();
    }
	common.changeCurrency(this)
  },
  components: {},
  props: {},
  methods: {
    setMainContent: function () {
      common.post('Wxapp_merchant&a=merchant_transrecord', {
        mer_id: this.mer_id
      }, "setListContent", this);
    },
    setListContent: function (result) {
      this.setData({
        record_list: result,
        isLoading: false
      });
      wx.hideToast();
    },
    showDetail: function (e) {
      this.setData({
        showIndex: e.currentTarget.dataset.index
      });
    },
    setData: function (obj) {
      let that = this;
      let keys = [];
      let val, data;
      Object.keys(obj).forEach(function (key) {
        keys = key.split('.');
        val = obj[key];
        data = that.$data;
        keys.forEach(function (key2, index) {
          if (index + 1 == keys.length) {
            that.$set(data, key2, val);
          } else {
            if (!data[key2]) {
              that.$set(data, key2, {});
            }
          }

          data = data[key2];
        });
      });
    }
  }
};
</script>
<style>
.noneList{
  margin-top:200rpx;
  text-align: center;
}

.jy_xq_box {
    width: 100%;
    overflow: hidden;
    border-bottom: 2rpx solid #dddddd;
    font-size: 26rpx;
}
.jy_zong, .jy_zong_cur {
    width: 96%;
    margin: 0 2%;
    height: 80rpx;
    line-height: 80rpx;
    position:relative;
}
.jy_zong:after {
    display: block;
    content: "";
    border-top:2rpx solid #838383;
    border-left:2rpx solid #838383;
    width:12rpx;
    height:12rpx;
    -webkit-transform: rotate(225deg);
    background-color: transparent;
    position: absolute;
    top: 28rpx;
    right:10rpx;
}
.margin_r {
    margin-right: 40rpx;
}


.jy_xq {
    width: 100%;
    overflow: hidden;
    padding:10rpx 0;
    background:white;
    color: #666666;
}
.jy_jl {
    width: 92%;
    padding: 0 4%;
    height: 48rpx;
    line-height: 48rpx;
}
</style>